A Sneak Peek at the Stable Values API

In this talk, we will demystify the work that is going on with the “StableValues API” with the associated battle cry “Codes like lazy initialization, performs like a constant.”

Some internal JDK classes rely heavily on the annotation jdk.internal.vm.annotation.@Stable to mark scalar and array fields whose values or elements will change at most once, thereby providing crucial performance, energy efficiency, and flexibility benefits. But the powerful @Stable annotation cannot be used directly in Java applications, thereby severely restricting its applicability.

The StableValue API rectifies this imbalance between internal and client code by providing safe wrappers around the @Stable annotation. Hence, all the important benefits of @Stable are now made available to regular Java developers and third-party library developers.

Learn how to create lazy Lists and Maps with the same performance as if their elements were constant values!

Make sure to check the JavaOne 2025 playlist.